package org.jiuling.local.tools.convert;

import org.jiuling.local.tools.exception.LocalToolsException;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 异常转换工具
 */
@Deprecated
public class ThrowableConvert {

    /** 私有构造方法，禁止创建对象 */
    private ThrowableConvert(){}

    /**
     * 异常堆栈转换为字符串
     * @param throwable 异常
     * @return 字符串堆栈
     */
    public static String throwableStackToString(Throwable throwable) throws LocalToolsException {
        try (StringWriter stringWriter = new StringWriter()){
            PrintWriter printWriter = new PrintWriter(stringWriter);
            throwable.printStackTrace(printWriter);
            return stringWriter.getBuffer().toString();
        } catch (IOException e) {
            throw new LocalToolsException("异常转换失败！");
        }
    }

}
